home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / buffr2.zip / BD3ARRAY.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  5KB  |  176 lines

  1. Unit BD3Array;  {Useable 3-Dimensional BufferedArrays}
  2. {$R-}
  3.  
  4. INTERFACE
  5. Uses BD3_Max;
  6.  
  7. Type
  8.   BD3_IntArray = Object (D3_BufferedArray)
  9.  
  10.                    Procedure Init (Max1,Max2,Max3,MaxBuffSize : LongInt;
  11.                                   FileName : String);
  12.  
  13.                    { BD3_xxxArrays are indexed 0..Max1-1, 0..Max2-1, 0..Max3-1}
  14.  
  15.                    Procedure Load (FileName : String;
  16.                                    Max1,Max2,Max3,MaxBuffSize : LongInt);
  17.  
  18.                    Procedure Accept (X,Y,Z : LongInt; I : Integer);
  19.  
  20.                    Procedure Retrieve (X,Y,Z : LongInt; Var I : Integer);
  21.  
  22.                    {NOTE: There is no reason why Retrieve could not be}
  23.                    {redefined as a function for atomic types such as Integer}
  24.  
  25.                    Procedure Copy (From : BD3_IntArray);
  26.                               {Target *MUST* already be initialized}
  27.                               {to the EXACT same parameters as From}
  28.                               {this will save checking for sufficient}
  29.                               {available Memory!}
  30.  
  31. (* no redefinition needed
  32.  
  33.                    Procedure Store;
  34.  
  35.                    Procedure Swap (X1,Y1,Z1,X2,Y2,Z2 : LongInt);
  36.                               {Swap the 1 and 2 Element}
  37.  
  38.                    Function MaxIndex (Index : Byte) : LongInt;
  39.                                      {Return the Max legal Index}
  40.                                      {for the Indexth Dimension}
  41.  
  42.                    Function MaxSize : LongInt;
  43.                                       {Report Number of Array Elements}
  44.                    Function ElemSize : Word;  {Report Element Size}
  45.                    Procedure Destroy;
  46. *)
  47.           End; {BD3_IntArray}
  48.  
  49.   BD3_RealArray = Object (D3_BufferedArray)
  50.  
  51.                    Procedure Init (Max1,Max2,Max3,MaxBuffSize : LongInt;
  52.                                   FileName : String);
  53.  
  54.                    Procedure Load (FileName : String;
  55.                                    Max1,Max2,Max3,MaxBuffSize : LongInt);
  56.  
  57.                    Procedure Accept (X,Y,Z : LongInt; I : Real);
  58.  
  59.                    Procedure Retrieve (X,Y,Z : LongInt; Var I : Real);
  60.  
  61.                    Procedure Copy (From : BD3_RealArray);
  62.  
  63.           End; {BD3_RealArray}
  64.  
  65. IMPLEMENTATION
  66.  
  67. Uses BND_Max;  {Obtain the definition of the DimensionPtr Type}
  68.  
  69. Procedure BD3_IntArray.Init;
  70. {NOTE: If ANY of the Max's is zero, ND_MAX.INIT will attempt}
  71. {to determine and allocate the maximum possible index.  If all}
  72. {are zero, then the largest possible evenly-indexed array will be allocated}
  73. {There is a POSSIBILITY of allocation errors if less than all are}
  74. {zero, but such errors will be detected and reported}
  75. Var
  76.   Temp : DimensionPtr;
  77.   I    : Byte;
  78. Begin
  79.   I := 0;
  80.   GetMem (Temp,3*SizeOf(LongInt));
  81.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  82.   Temp^[I] := Max2; I := 2;  {with Range-checking off!!}
  83.   Temp^[I] := Max3;
  84.   D3_BufferedArray.Init (Temp,SizeOf(Integer),MaxBuffSize,FileName);
  85.   FreeMem (Temp,3*SizeOf(LongInt));
  86. End;
  87.  
  88. Procedure BD3_IntArray.Load;
  89. Var
  90.   Temp : DimensionPtr;
  91.   I    : Byte;
  92. Begin
  93.   I := 0;
  94.   GetMem (Temp,3*SizeOf(LongInt));
  95.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  96.   Temp^[I] := Max2; I := 2;  {with Range-checking off!!}
  97.   Temp^[I] := Max3;
  98.   D3_BufferedArray.Load (FileName,SizeOf(Integer),MaxBuffSize,3,Temp);
  99.   FreeMem (Temp,3*SizeOf(LongInt));
  100. End;
  101.  
  102. Procedure BD3_IntArray.Accept (X,Y,Z : LongInt; I : Integer);
  103. Var
  104.   Temp : Integer;
  105. Begin
  106.   Temp := I;
  107.   D3_BufferedArray.Accept (X,Y,Z,Temp,SizeOf(Integer))
  108. End;
  109.  
  110. Procedure BD3_IntArray.Retrieve (X,Y,Z : LongInt; Var I : Integer);
  111. Var
  112.   Temp : Integer;
  113. Begin
  114.   D3_BufferedArray.Retrieve (X,Y,Z,Temp,SizeOf(Integer));
  115.   I := Temp
  116. End;
  117.  
  118. Procedure BD3_IntArray.Copy (From : BD3_IntArray);
  119. {Redefined purely for type-checking}
  120. Begin
  121.   D3_BufferedArray.Copy (From)
  122. End;
  123.  
  124. {**********************************************************************}
  125.  
  126. Procedure BD3_RealArray.Init;
  127. Var
  128.   Temp : DimensionPtr;
  129.   I    : Byte;
  130. Begin
  131.   I := 0;
  132.   GetMem (Temp,3*SizeOf(LongInt));
  133.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  134.   Temp^[I] := Max2; I := 2;  {with Range-checking off!!}
  135.   Temp^[I] := Max3;
  136.   D3_BufferedArray.Init (Temp,SizeOf(Real),MaxBuffSize,FileName);
  137.   FreeMem (Temp,3*SizeOf(LongInt));
  138. End;
  139.  
  140. Procedure BD3_RealArray.Load;
  141. Var
  142.   Temp : DimensionPtr;
  143.   I    : Byte;
  144. Begin
  145.   I := 0;
  146.   GetMem (Temp,3*SizeOf(LongInt));
  147.   Temp^[I] := Max1; I := 1;  {Have to fool the compiler, even}
  148.   Temp^[I] := Max2; I := 2;  {with Range-checking off!!}
  149.   Temp^[I] := Max3;
  150.   D3_BufferedArray.Load (FileName,SizeOf(Real),MaxBuffSize,3,Temp);
  151.   FreeMem (Temp,3*SizeOf(LongInt));
  152. End;
  153.  
  154. Procedure BD3_RealArray.Accept (X,Y,Z : LongInt; I : Real);
  155. Var
  156.   Temp : Real;
  157. Begin
  158.   Temp := I;
  159.   D3_BufferedArray.Accept (X,Y,Z,Temp,SizeOf(Real))
  160. End;
  161.  
  162. Procedure BD3_RealArray.Retrieve (X,Y,Z : LongInt; Var I : Real);
  163. Var
  164.   Temp : Real;
  165. Begin
  166.   D3_BufferedArray.Retrieve (X,Y,Z,Temp,SizeOf(Real));
  167.   I := Temp
  168. End;
  169.  
  170. Procedure BD3_RealArray.Copy (From : BD3_RealArray);
  171. Begin
  172.   D3_BufferedArray.Copy (From)
  173. End;
  174.  
  175. BEGIN
  176. END.